package game_elements_layer.players_stuff;

import game_elements_layer.guys_stuff.Guys;
import game_elements_layer.field_stuff.locations_stuff.Locations;
import game_elements_layer.productions_stuff.Productions;
import game_elements_layer.resourses_stuff.*;

import java.awt.Color;
import java.util.ArrayList;

/**
 * Created with IntelliJ IDEA.
 * User: vych0914
 * Date: 06.10.14
 * Time: 16:56
 * To change this template use File | Settings | File Templates.
 */
public class Player {

    private String name;
    private Color color;

    private Money money;
    private Alcohol alcohol;
    private Guns guns;
    private Drugs drugs;
    private ResourceToMoneyConverter resourceToMoneyConverter;
    private ArrayList<Guys> guys;
    private ArrayList<Productions> productions;


    public Player(String name, Color color, int startMoney, int startAlcohol, int startGuns, int startDrugs, int countOfGuys) {

        this.name = name;
        this.color = color;

        this.money = new Money(startMoney);
        this.alcohol = new Alcohol(startAlcohol);
        this.guns = new Guns(startGuns);
        this.drugs = new Drugs(startDrugs);
        this.productions = new ArrayList<Productions>();
        this.guys = new ArrayList<Guys>();
        for (int i = 0; i < countOfGuys; i++) {
            this.guys.add(new Guys(i, this));
        }
    }

    public ArrayList<Productions> getProductions() {
        return productions;
    }

    public void payMoney(int amount) {
        this.money.setAmount(this.money.getAmount() - amount);
    }

    public void payAlcohol(int amount) {
        this.alcohol.setAmount(this.alcohol.getAmount() - amount);
    }

    public void payGuns(int amount) {
        this.guns.setAmount(this.guns.getAmount() - amount);
    }

    public void payDrugs(int amount) {
        this.drugs.setAmount(this.drugs.getAmount() - amount);
    }

    public void earnMoney(int amount) {
        this.money.setAmount(this.money.getAmount() + amount);
    }

    public void earnAlcohol(int amount) {
        this.alcohol.setAmount(this.alcohol.getAmount() + amount);
    }

    public void earnGuns(int amount) {
        this.guns.setAmount(this.guns.getAmount() + amount);
    }

    public void earnDrugs(int amount) {
        this.drugs.setAmount(this.drugs.getAmount() + amount);
    }

    public Money getMoney() {
        return money;
    }

    public ArrayList<Locations> getControlledLocations() {
        ArrayList<Locations> result = new ArrayList<Locations>();
        for (Guys g : this.guys) {
            if ((g.getCurrentLocation() != null)&&(!result.contains(g.getCurrentLocation()))) result.add(g.getCurrentLocation());
        }
        if (!this.productions.isEmpty()){
            for (Productions p:this.productions){
                if (!result.contains(p.getLocation())) result.add(p.getLocation());
            }
        }
        return result;
    }

    @Override
    public String toString() {
        return "Player " + name;
    }
}
